<?php
    $this->headTitle($this->site_name.' - Manage Clients');
?>

<script type="text/javascript" src="/js/ui/jquery.ui.core.min.js"></script>
<script type="text/javascript" src="/js/ui/jquery.ui.widget.min.js"></script>
<script type="text/javascript" src="/js/ui/jquery.ui.mouse.min.js"></script>
<script type="text/javascript" src="/js/ui/jquery.ui.draggable.min.js"></script>
<script type="text/javascript" src="/js/ui/jquery.ui.droppable.min.js"></script>
<script type="text/javascript" src="/js/ui/jquery.ui.sortable.min.js"></script>
<script type="text/javascript" src="/js/jquery.validate.js"></script>

<style>
	.draggable1, .draggable2 { cursor:pointer;}
	.sortable { list-style-type: none; margin: 0; padding: 0;  }
	.sortable li { margin: 0 3px 3px 3px;  }
	.sortable li a { position: absolute;  }
	input{ float: left; margin-top : 4px }
	select{  margin-top : 4px }
	input[type="checkbox"]{ float: left; margin : 5px }
	label { float:left; }
	div .left-column {width:45%;float:left;margin-left:20px;}
</style>

<script>
<?php
	echo "var page_uri='".$_SERVER['REQUEST_URI']."';\n";
	echo "var services=new Array();\n";
	echo "var departments=new Array();\n";
	echo "var serviceurl=new Array();\n";
	$all_services = $this->all_services;
	foreach ($all_services as $key => $value){
		echo "services['".$value['dpt_id']."']='".$value['icon']."';\n";
		echo "departments['".$value['dpt_id']."']='".$value['dpt_name']."';\n";
		echo "serviceurl['".$value['dpt_id']."']='".$value['service_url']."';\n";
	} 
?>

	function slide(id){
		if ($("#"+id).hasClass('down')){
			$("#"+id).removeClass('down');
			$("#"+id+"_expand").html(' + ');
			$("#"+id).hide();
		}else{
			$("#"+id).addClass('down');
			$("#"+id+"_expand").html(' - ');
			$("#"+id).show();
		}
	}

	function disableClient(id){
		location=page_uri+'?act=disable&id='+id;
	}

	function suspendClient(id){
		location=page_uri+'?act=suspend&id='+id;
	}
	
	function activateClient(id){
		location=page_uri+'?act=activate&id='+id;
	}
</script>

<script type="text/javascript">
	$(document).ready(function(){
		$('.noscroll').click(function(event) {
			event.preventDefault();
		});
		$( "#sortable1" ).sortable();
		$( "#sortable1" ).disableSelection();
		
		$( ".draggable2" ).draggable({revert: true});		  
	    
	  });

</script>  

<?php if (!empty($this->success_msg)):?>
<div class="response-msg success ui-corner-all"><?php echo $this->success_msg;?></div>
<?php endif ?>

<?php if (!empty($this->error_msg)):?>
<div class="response-msg error ui-corner-all"><?php echo $this->error_msg;?></div>
<?php endif ?>


<div id="dashboard">

<h2>Clients Management</h2>
 
<div  style="margin-top:-16px;border-bottom:1px solid #ccc;"><!-- search form starts here-->

<form action="/client/manager" method="post" name="search_account_form">
<table>
	<tr>
		<td width="20%" align=left valign=middle>Account Email:<?php echo $this->form2->email;?></td>
		<td width="17%" align=left valign=middle>DPT id:<br><?php echo $this->form2->dpt_id;?></td>
		<td width="17%" align=left valign=middle>Login Account ID:<br><?php echo $this->form2->dpt_account_login;?></td>
    	<td width="17%" align=left valign=middle>Login Area:<br><?php echo $this->form2->login_area;?></td>
    	<td width="17%" align=left valign=middle>Role:<br><?php echo $this->form2->role;?></td>
	    <td widht="12%"><?php echo $this->form2->search;?></td>
	</tr>
</table>
</form>
</div>
<!-- search form ends here-->

 
 
<div style="float:left; width:98%; margin:0 0 20px 4px;">
<h3>All Clients: <!--  a href="#" class="grey-btn" style="float:right;display:inline;" onclick="addNewClient();"><span class="ui-title">Add New Client</span></a--></h3>

<div  id="droppable1" style="font-size:12px;font-weight:bold;">		

	<ul id="sortable1">
<?php if (count($this->all_clients)>0):?>
	<?php 
	$i=$this->start;
	foreach($this->all_clients as $index => $item ){
	//foreach ($this->paginator as  $index => $item){
		$i++;
		$status=$item['status'];
		switch($status){
			case 'Pending': $status_str='<div class=left style="margin:-3px 0 0 20px;"><a class=btn onclick="if (confirm(\'Are you sure to activate this client?\n'.$item['email'].'\')) { activateClient(\''.$index.'\');}">Activate</a></div><div class=left style="margin:-3px 0 0 20px;"><a class=btn onclick="if (confirm(\'Are you sure to suspend this client?\n'.$item['email'].'\')) { suspendClient(\''.$index.'\');}">Suspend</a></div>'; break;
			case 'Active': $status_str='<div class=left style="margin:-3px 0 0 20px;"><a class=btn onclick="if (confirm(\'Are you sure to suspend this client?\n'.$item['email'].'\')) { suspendClient(\''.$index.'\');}">Suspend</a></div>'; break;
			case 'Suspend': $status_str='<div class=left style="margin:-3px 0 0 20px;"><a class=btn onclick="if (confirm(\'Are you sure to activate this client?\n'.$item['email'].'\')) { activateClient(\''.$index.'\');}">Activate</a></div>'; break;
			default: $status='';break;
		}
		
		if ($item['role']=='manager')
			$role_str='<div style="margin:4px 5px 0 0;float:left;"><img src="/images/Check-32.png" height=16> Manager</div>';
		else
			$role_str='';
		
		echo '<li title="Click to edit" style="padding:0;"><div><div class=left style="width:360px;">'.$i.') Client Email:  <a href="/client/manager/to-client/id/'.$index.'" target=_blank>'.$item['email'].'</a></div><div class=left style="width:100px">status:'.$item['status'].'</div>'.$status_str.'<div style="float:right;">'.$role_str.'</div>';
		echo '<div class="clearfix"></div><div>&nbsp;&nbsp;&nbsp;&nbsp;<b id="'.$index.'_expand"> + </b><a href="javascript:void();" class="noscroll" onclick="slide(\''.$index.'\');">Services: '.count($item['services']).'</a></div>';
		echo '<ul id="'.$index.'" style="display:none;">';
		foreach($item['services'] as $key => $value){
			echo '<li id="'.$value['icon'].'" style="float:left;margin:10px;display:inline;">';
			echo '<div><a href="/client/manager/to-client/id/'.$value['client_id'].'" target=_blank>'.$value['dpt_name'].'</a><span></span><p><a style="color:black;" href="/client/manager/to-client/id/'.$value['client_id'].'" target=_blank>'.$value['dpt_account_login'].'</a></p></div>';
			echo '</li>';
		}
		echo '</ul>';
		echo '</div>';
		echo '</li>';
		echo '<div class="clearfix" style="margin-bottom:10px;"></div>';
	}
	?>
		
<?php else: ?>
	<li>No client right now.</li>
<?php endif ?>
	</ul>

</div>
 
</div>

<div align=center style="margin:10px 0;"><?php echo $this->paginator; ?></div>


</div>